package job;

import org.quartz.*;

import java.text.SimpleDateFormat;
import java.util.Date;

@PersistJobDataAfterExecution //进行job的持久化，不会频繁的创建JOB，可存储和累计里面的数据
public class HelloJob implements Job {
    public HelloJob(){
        System.out.println("--->Job重新创建");
    }
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {

        JobDetail job = jobExecutionContext.getJobDetail();
        System.out.println("---->job.getDescription()："+job.getDescription());
        System.out.println("---->job.getJobDataMap().toString()："+job.getJobDataMap().toString());
        System.out.println("---->job.getJobDataMap().getString('message')："+job.getJobDataMap().getString("message"));
        System.out.println("---->job.getJobClass().getSimpleName()："+job.getJobClass().getSimpleName());
        System.out.println("---->job.getJobClass().getName()："+job.getJobClass().getName());
        System.out.println("---->job.getKey().getName()："+job.getKey().getName());
        System.out.println("---->job.getKey().getGroup()："+job.getKey().getGroup());
        System.out.println("---->job.getKey().getClass()："+job.getKey().getClass());

        Trigger trigger = jobExecutionContext.getTrigger();
        String message = trigger.getJobDataMap().getString("message");
        System.out.println("---->trigger.getJobDataMap().toString()："+message);

        // 格式化时间
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(date);
        System.out.println("--->任务调度：" + format);

        // 时间进行延迟操作
        Date startDate = new Date();
        startDate.setTime(3000);// 推迟3秒
    }
}
